package com.yunform.framework.util.jxls;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

public class ExcelUtil {
	
	public static class ExcelTable{
		private String[] titles;
		private List<Object[]> rows;
		public String[] getTitles() {
			return titles;
		}
		public void setTitles(String[] titles) {
			this.titles = titles;
		}
		public List<Object[]> getRows() {
			return rows;
		}
		public void setRows(List<Object[]> rows) {
			this.rows = rows;
		}
	}
	
	/**
	 * 读取excel为一个data table
	 * @param is
	 * @return
	 */
	public static  ExcelTable read(InputStream is){
		try{
		ExcelReader excelReader = new ExcelReader(is);
		ExcelTable excelTable = new ExcelTable();
		excelTable.setTitles(excelReader.readExcelTitle());
		List<Object[]> rows = excelReader.readExcelContent();
		excelTable.setRows(rows);
		return excelTable;
		}catch(Exception e ){
			throw new ReadExcelException();
		}
	}
	
	/**
	 * 生成excel
	 * @param sheetName
	 * @param headers
	 * @param rows
	 * @param outputStream
	 */
	public static void genExcel(String sheetName,List<String> headers,List<Object[]> rows,OutputStream outputStream){
		try {
			ExcelWriter.write(sheetName, headers, rows, outputStream);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}	
